//
//  HScrollSectionController.m
//  MY_IGList_demo
//
//  Created by mac on 2019/3/21.
//  Copyright © 2019 Yilian. All rights reserved.
//

#import "HScrollSectionController.h"
#import "HScrollCollectionViewCell.h"
#import "ACollectionSectionController.h"
#import "GoodsModel.h"
@interface HScrollSectionController ()<IGListAdapterDataSource>
@property (nonatomic,strong) IGListAdapter *adapter;
@property (nonatomic,strong) GoodsModel *goodsmodel;
@end

@implementation HScrollSectionController



- (instancetype)init{
    if (self = [super init]) {
        self.inset = UIEdgeInsetsMake(0, 0, 10, 0);
    }
    return self;
}

- (IGListAdapter *)adapter {
    if (!_adapter) {
        _adapter = [[IGListAdapter alloc] initWithUpdater:[IGListAdapterUpdater new] viewController:self.viewController workingRangeSize:3];
        _adapter.dataSource = self;
    }
    
    return _adapter;
}

- (CGSize)sizeForItemAtIndex:(NSInteger)index {
    
    return CGSizeMake(self.collectionContext.containerSize.width, self.collectionContext.containerSize.height);
}

- (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index {
    HScrollCollectionViewCell *cell = [self.collectionContext dequeueReusableCellOfClass:[HScrollCollectionViewCell class] forSectionController:self atIndex:index];
    self.adapter.collectionView = cell.collectionView;
    return cell;
}

- (void)didUpdateToObject:(id)object {
    self.goodsmodel = object;
}

//数据model在 自己对应的viewcontroller中进行设置
- (NSArray<id <IGListDiffable>> *)objectsForListAdapter:(IGListAdapter *)listAdapter{
    NSMutableArray *arr = [NSMutableArray array];
    NSArray *descarr = @[@"尽疑无路,柳暗花明又一村",@"花明又一村柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村",@"山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路",@"山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路,柳暗花明又一村山重水尽疑无路"];
    for (int i = 0; i < 4; i++) {
        GoodsModel *goods_model = [GoodsModel new];
        goods_model.img_name = @"Image";
        goods_model.price = [NSString stringWithFormat:@"$ %d",i];;
        goods_model.desc = descarr[i];
        goods_model.title = [NSString stringWithFormat:@"Apple Pay%d",i];
        [arr addObject:goods_model];
    }
    NSArray *array = [NSArray arrayWithArray:arr];
    return array;
}

- (IGListSectionController *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object{
    return [ACollectionSectionController new];
}

- (nullable UIView *)emptyViewForListAdapter:(IGListAdapter *)listAdapter{
    return nil;
}

@end
